<template>
  <basic-container :btnFlag=true>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <el-form label-width="130px" style="padding-right: 30px;">
      <el-row>
        <el-col :span="16"  style="margin-top: 27px;">
          <el-form-item class="form-item" label="规划名称 :" prop="title">
            <span>{{title}}</span>
          </el-form-item>
        </el-col>
        <el-col :span="4" v-if="pmuc!=null">
          <el-button size="small" type="success" style="margin-top: 31px" @click="resultDetailTemp()">规划详情</el-button>
        </el-col>
      </el-row>
      </el-form>

      <div style="float: right;margin-right: 5px;">
        <el-button type="primary" size="mini" @click.stop="addModel(pmuc)">新增模版</el-button>
      </div>
      <avue-crud
        :data="modelListData"
        :option="option"
        :page="page"
        :table-loading="tableLoading"
        @on-load="getModelPageList"
        @refresh-change="refreshChange"
        class="avuecrud"
      >
        <template slot-scope="scope" slot="menu">
          <div class="menu-title" @click.stop="editModel(scope.row,scope.index)">
            <i class="iconfont iconview icon-primary"></i>
            <p class="menu-title-text">编辑</p>
          </div>
         <div class="menu-title" @click.stop="disposeworkingitem(scope.row,scope.index)">
            <i class="iconfont iconalter icon-warning"></i>
            <p class="menu-title-text">配置监测项</p>
          </div>
        </template>
      </avue-crud>

    </div>
  </basic-container>
</template>

<script>
  import {PIM_DIC} from '@/const/dict'
  import { modelPageList } from "@/api/pim/pim";
  import {resultDetail} from "@/api/planning/result";
  export default {
    name: "dutyAnalysis",
    created(){
        this.achievementId = this.$route.params.id;
        this.getDetailData();
    },
    data(){
      return{
        headerData:{
          title:'责任分解'
        },
        pmuc:'',// 规划编码
        title:'',//规划名称
        achievementIdTemp:0,
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10// 每页显示多少条
        },
        modelListData: [],
        option: {
          page: true,
          addBtn: false,
          editBtn: false,
          indexLabel: "序号",
          index: true,
          indexWidth:70,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          menuWidth:200,
          keyId: "id",
          column: [{
            label: "模版名称",
            prop: "name",
            cell: true
          },
            {
              label: "模版类型",
              width:250,
              prop: "category",
              dicData: PIM_DIC.CATEGORY,
              cell: true
            },
          ]
        },
        tableLoading: false

      }
    },
    methods:{
      // 获取详情信息
      getDetailData(){
        resultDetail(this.$route.params.id).then(response => {
          this.getresultDetail(response);
        })
      },
      async  getresultDetail(response){
        if(response.data.code == '0') {
          var records = response.data.data;
          this.pmuc = records.pmuc;
          this.title=records.title;
          this.achievementIdTemp = records.achievementId;
        }
      },
      //规划详情
      resultDetailTemp(){
        let src = `/searchDetail/detail/${this.achievementIdTemp}`;
        this.$router.push({
          path: src
        })
      },
      // 配置监测项
      disposeworkingitem(row,index){
        let src = `/pim/workingItem/index/${row.id}`;
        this.$router.push({
          path: src
        })
      },
      //新增模版
      addModel(pmuc){
        let src = `/pim/addModel/detail/${pmuc}`;
        this.$router.push({
          path: src,
          query: {
            titleName: this.title
          }
        })
      },
     //修改模版
      editModel(row,index){
        let src = `/pim/editModel/detail/${row.id}`;
        this.$router.push({
          path: src
        })
      },
      getModelPageList(page){
        this.tableLoading = true;
        modelPageList(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
          states:this.state,
          pmuc:this.$route.query.pmuc,
        },)).then(response => {
          this.modelListData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false
        })
      },

    }
  }
</script>

<style lang="scss" scoped>
  .card-border {
    border: 1px solid #d2d2d2;
    padding: 12px;
  }
  .form-submit {
    text-align: center;
  }
  .form-item{
    font-weight: 600;
  }
</style>
